package search;
import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class SearchMapper   extends Mapper<LongWritable, Text, Text, Text>{

    private final static Text outputKey = new Text();
    private final static Text outputValue = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line, ",");

        if (tokenizer.hasMoreTokens()) { // 确保至少有两列
            String firstColumn = tokenizer.nextToken().trim(); // 第一列
            String secondColumn = tokenizer.nextToken().trim(); // 第二列

            // 检查第二列是否包含"青岛市"
            if (secondColumn.contains("青岛市")) {
                outputKey.set("包含青岛市");
                outputValue.set(firstColumn + "," + secondColumn);
            } else {
                outputKey.set("不包含青岛市");
                outputValue.set(firstColumn + "," + secondColumn);
            }

            context.write(outputKey, outputValue);
        }
    }
}
